package com.myk.game.gobangchess.ai.gravityfour;

public class KillJudging4plus {
    
    public static int[] killJudgingDeep4(int[][] board, int direction, int playerTurn, int dirChanged) {
        int isKillDeep4 = 0;
        int killPoint = -1;
        int killDeep = -1;
        int[] result = KillJudging3plus.killJudgingDeep3(board, direction, playerTurn, dirChanged);
        int isKillDeep3 = result[0];

        if (isKillDeep3 != 1) {
            for (int x = 1; x <= 10; x++) {

                Object[] pointSettingResult = PointSetting.pointSetting(board, direction, playerTurn, x, dirChanged);
                int set_succ = (int) pointSettingResult[0];
                int[][] new_board = (int[][]) pointSettingResult[1];
                int new_direction = (int) pointSettingResult[2];
                int new_dir_changed = (int) pointSettingResult[3];
                if (set_succ == 1) {

                    if (true) { 
                        int isKillDeep2Check = KillJudging2plus.killJudgingDeep2(new_board, new_direction, -playerTurn, new_dir_changed)[0];
                        if (isKillDeep2Check != 1) {
                            int stillKilling = 1;
                            for (int x1 = 1; x1 <= 10; x1++) {
                                if(stillKilling == 1){
                                    Object[] setSuccessResult1 = PointSetting.pointSetting(new_board, new_direction, -playerTurn, x1, new_dir_changed);
                                    int setSuccess1 = (int) setSuccessResult1[0];
                                    int[][] newBoard1 = (int[][]) setSuccessResult1[1];
                                    int new_direction1 = (int) setSuccessResult1[2];
                                    int new_dir_changed1 = (int) setSuccessResult1[3];
                                    if (setSuccess1 == 1) {
                                        int isKillDeep3Check1 = KillJudging3plus.killJudgingDeep3(newBoard1, new_direction1, playerTurn, new_dir_changed1)[0];
                                        stillKilling *= isKillDeep3Check1;
                                    }
                                }
                            }

                            if (stillKilling == 1) {
                                isKillDeep4 = 1;
                                killPoint = x;
                                killDeep = 4;
                                break;
                            }
                        }
                    }
                }
            }
        }else{
            isKillDeep4 = result[0];
            killPoint = result[1];
            killDeep = result[2];
        }

        int[] output = {isKillDeep4, killPoint, killDeep};
        return output;
    }
}
